package com.test.deencredit.view_deencredit.process_widget_deencredit;

import android.annotation.SuppressLint;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.test.deencredit.R;
import com.test.deencredit.base_deencredit.BaseProcessWidgetManager_deencredit;
import com.test.deencredit.bean_deencredit.process_deencredit.ProcessInfo_Data_deencredit;
import com.test.deencredit.dialog_deencredit.DatePickerDialog_deencredit;
import com.test.deencredit.util_deencredit.http_deencredit.HttpUtil_deencredit;


public class DateSelectViewManager_deencredit extends BaseProcessWidgetManager_deencredit {

    private TextView titleTv_deencredit;
    private TextView inputTv_deencredit;

    public DateSelectViewManager_deencredit(View view, ProcessInfo_Data_deencredit data, String page){
        super(view,data,page);
    }

    @SuppressLint("SetTextI18n")
    @Override
    protected void init_deencredit(){

        titleTv_deencredit = mView_deencredit.findViewById(R.id.vpds_tv_title);
        inputTv_deencredit = mView_deencredit.findViewById(R.id.vpds_tv_input);

        setTitle_deencredit(mData_deencredit.getTitle_deencredit());
        inputTv_deencredit.setHint(mData_deencredit.getHint_deencredit());

        mView_deencredit.findViewById(R.id.vpds_view_click).setOnClickListener(v -> {

            HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit, mData_deencredit.getParamName_deencredit().toUpperCase()+"_CLICK","");

            new DatePickerDialog_deencredit(
                    mView_deencredit.getContext(),
                    mData_deencredit.getTitle_deencredit(),
                    date -> {
                        inputTv_deencredit.setText(date);
                        HttpUtil_deencredit.getInstance_deencredit().saveBuriedPoint_deencredit(page_deencredit, mData_deencredit.getParamName_deencredit().toUpperCase()+"_CLICK", getInput_deencredit());
                    }
            ).show();
        });

    }

    @Override
    public boolean checkInput_deencredit() {
        if (!mData_deencredit.isMustInput_deencredit()) return true;
        return !TextUtils.isEmpty(inputTv_deencredit.getText());
    }

    @Override
    public String getInput_deencredit() {
        return inputTv_deencredit.getText().toString();
    }

    public void setTitle_deencredit(String title){
        if (TextUtils.isEmpty(title)) titleTv_deencredit.setVisibility(View.GONE);
        else {
            titleTv_deencredit.setVisibility(View.VISIBLE);
            titleTv_deencredit.setText(title);
        }
    }

}
